package org.qqcui.designpattern.patterns.state;

import java.util.Random;

/**
 * 可抽奖状态
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2022/5/7 14:17
 **/
public class CanRaffleState extends State {

    private RaffleActivity activity;

    public CanRaffleState(RaffleActivity activity) {
        this.activity = activity;
    }

    @Override
    void deduceScore() {
        System.out.println("已经扣除了50积分，可以抽奖状态");
    }

    @Override
    boolean raffle() {
        System.out.println("正在抽奖");
        // 中奖概率10%
        Random random = new Random();
        int i = random.nextInt(10);
        if (i == 0) {
            // 中奖，设置状态为发送奖品状态
            activity.setState(activity.getDispenseState());
            return true;
        } else {
            System.out.println("很遗憾，未中奖，下次再接再厉哦");
            // 未中奖，设置状态为未抽奖状态
            activity.setState(activity.getNoRaffleState());
        }
        return false;
    }

    @Override
    void dispensePrize() {
        System.out.println("正在抽奖，抽中以后才可以发奖哦");
    }
}
